package com.base.vistter.iframe.inverter.controller;

import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.InverterRelation;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.InverterRelationService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/relation")
public class InverterRelationController {

    @Resource(name = "inverterRelationService")
    private InverterRelationService inverterRelationService;

    @GetMapping()
    public Result<InverterRelation> get() throws IframeException {
        return Result.ok(inverterRelationService.selectOne());
    }

    @PutMapping()
    public Result<Boolean> update(@RequestBody InverterRelation inverterRelation) throws IframeException {
        if (inverterRelation.getId() == null) {
            inverterRelationService.save(inverterRelation);
        } else {
            inverterRelationService.update(inverterRelation);
        }
        return Result.ok(true);
    }

}
